//
//  JGHelpViewController.m
//  WangYLottery
//
//  Created by JJetGu on 15/8/29.
//  Copyright (c) 2015年 JJetGu. All rights reserved.
//

#import "JGHelpViewController.h"

#import "JGSettingArrowItem.h"
#import "JGSettingCell.h"

#import "JGSettingGroup.h"
#import "JGSettingItem.h"

#import "JGHelp.h"
#import "JGHtmlViewController.h"
#import "JGNavigationController.h"

@interface JGHelpViewController ()

@property (nonatomic, strong) NSMutableArray *htmls;

@end

@implementation JGHelpViewController

-(NSMutableArray *)htmls
{
    if (!_htmls) {
        self.htmls = [NSMutableArray array];
        
        NSString *fileName = [[NSBundle mainBundle] pathForResource:@"help.json" ofType:nil];
        NSData *data = [NSData dataWithContentsOfFile:fileName];
        
        NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        for (NSDictionary *dict in jsonArray) {
            JGHelp *help = [JGHelp htmlWithDict:dict];
            [_htmls addObject:help];
        }
    }
    
    return _htmls;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addGroup0];
}

- (void)addGroup0
{
    NSMutableArray *items = [NSMutableArray array];
    for (JGHelp *help in self.htmls) {
        JGSettingArrowItem *item = [JGSettingArrowItem itemWithIcon:@"" title:help.title destVcClass:nil];
        [items addObject:item];
    }
    
    JGSettingGroup *group0 = [[JGSettingGroup alloc] init];
    group0.items = items;
    
    [self.dataList addObject:group0];
}


// 重写tableView的点击
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
     // 取出每一行对应的Html模型
    JGHelp *help = self.htmls[indexPath.row];
    
    JGHtmlViewController *htmlVC = [[JGHtmlViewController alloc] init];
    htmlVC.title = help.title;
    htmlVC.help = help;
    
    JGNavigationController *nav = [[JGNavigationController alloc] initWithRootViewController:htmlVC];
    [self presentViewController:nav animated:YES completion:nil];
    
    
}

@end
